﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using System.Drawing;
namespace HB.WpfEx
{
    public static class MapEx
    {
        public static Bitmap ToBitmap(this WriteableBitmap map)
        {
            if (map.Format == System.Windows.Media.PixelFormats.Bgr32)
            {
                return new Bitmap(map.PixelWidth, map.PixelHeight, map.BackBufferStride, System.Drawing.Imaging.PixelFormat.Format32bppArgb, map.BackBuffer);
            }
            if (map.Format == System.Windows.Media.PixelFormats.Bgr24)
            {
                return new Bitmap(map.PixelWidth, map.PixelHeight, map.BackBufferStride, System.Drawing.Imaging.PixelFormat.Format24bppRgb, map.BackBuffer);
            }
            throw new Exception("only support bgr32 or bgr24");
        }
        
    }
}
